package com.yisu.expressway.manager.website.controller.goodsArchives;

import com.yisu.expressway.ewf.common.web.JsonResult;
import com.yisu.expressway.ewf.entity.GoodsArchives;
import com.yisu.expressway.ewf.entity.GoodsSpecification;
import com.yisu.expressway.ewf.entity.SpecificationGoods;
import com.yisu.expressway.manager.core.service.ISpecificationGoodsService;
import com.yisu.expressway.manager.website.controller.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static com.yisu.expressway.ewf.common.enums.ResponseCode.FAILURE;
import static com.yisu.expressway.ewf.common.enums.ResponseCode.SUCCESS;

/**
 * Created by xlt on 2017/4/25.
 */
@Controller
@RequestMapping(value = "/specificationGoods")
public class SpecificationGoodsController extends BaseController {
    @Resource
    private ISpecificationGoodsService iSpecificationGoodsService;

    /**
     * 添加规格商品
     *
     * @param specificationGoods 商品档案信息
     * @return 状态
     */
    @RequestMapping(value = "/modifySpecificationGoods.json", produces = "application/json; charset=utf-8")
    @ResponseBody
    public JsonResult modifySpecificationGoods(HttpServletRequest request, SpecificationGoods specificationGoods) {
        try {
            if (StringUtils.isEmpty(specificationGoods.getCategoryCode() + "") || StringUtils.isEmpty(specificationGoods.getGoodsNo() + "") || StringUtils.isEmpty(specificationGoods.getPrice() + "")
                    || StringUtils.isEmpty(specificationGoods.getInventoryNum() + "") || StringUtils.isEmpty(specificationGoods.getSalesVolume() + "")) {
                return new JsonResult(FAILURE.code, "参数不完整！");
            }
            if (iSpecificationGoodsService.modifySpecificationGoods(specificationGoods)) {
                return new JsonResult(SUCCESS.code, "操作成功");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new JsonResult(FAILURE.code, "网络君泡妞去了.....");
    }
}
